using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Linq.Extensions;
using Abp.Domain.Repositories;
using Microsoft.EntityFrameworkCore;
using Sunlit.House.Buy.Dto;
using Abp.Extensions;
using Sunlit.House.Authorization;

namespace Sunlit.House.Buy
{
    public class GroupBuyTypeAppService: AsyncCrudAppService<GroupBuyType,GroupBuyTypeDto,long,GetAllGroupBuyTypeInput,
        CreateGroupBuyTypeInput,UpdateGroupBuyTypeInput>,IGroupBuyTypeAppService
    {
        public GroupBuyTypeAppService(IRepository<GroupBuyType,long> repository):base(repository)
        {
        }
        protected override IQueryable<GroupBuyType> CreateFilteredQuery(GetAllGroupBuyTypeInput input)
        {
            return base.CreateFilteredQuery(input)
                .WhereIf(!input.Name.IsNullOrWhiteSpace(), t => t.Name.Contains(input.Name));
        }
        public async Task<List<GroupBuyTypeDto>> GetAllListAsync()
        {
            var list = await Repository.GetAllListAsync();

            return ObjectMapper.Map<List<GroupBuyTypeDto>>(list);
        }
        public async Task<Dictionary<long,string>> GetAllDicAsync()
        {
           return await Repository.GetAll().ToDictionaryAsync(x => x.Id, x => x.Name);
        }
    }
}
